/* *
 *
 * 判断是否登陆
 *
 *
 * */

import { publicMsg } from "./publicMsg.js"

export  const isLogin = function(_this,edition){
	console.log("运行了登陆判断")
	var sTime = localStorage.getItem("start_time");

	var eTime = localStorage.getItem("end_time");

	var time = Date.parse(new Date())/1000;

	var access_token = localStorage.getItem("access_token");

	if(access_token!=null){
			if(eTime-time<3600){
						var weburl = "/recruitserver/api"+'/v1/'+"refresh_token";//刷新token

						var refresh_token = localStorage.getItem("refresh_token");

						var expire_time = localStorage.getItem("expire_time");

						var params = { "refresh_token":refresh_token,"expire_time":expire_time }
						//刷新torken
						var refarsh = function(){
										_this.axios({
											url: weburl,
											method: 'post',
											data: params,
											headers: {
												'Content-Type': 'application/json'
											},
										}).then(function(res) {
												if(res.data.code){
													if(res.data.code==102){
														localStorage.clear();
														_this.$Message.error("登陆验证信息失效，请重新登陆");
														_this.$router.push({path: '/'});
													}
													else{
														localStorage.clear();
														_this.$Message.error(publicMsg(res.data.code));
														_this.$router.push({path: '/'});
													}
												}else{
													var start_time = Date.parse(new Date())/1000;
													var end_time = Date.parse(new Date())/1000 + res.data.data.expire_time;
													localStorage.setItem("access_token",res.data.data.access_token);
													localStorage.setItem("refresh_token",res.data.data.refresh_token);
													localStorage.setItem('expire_time',res.data.data.expire_time);
													localStorage.setItem("start_time",start_time);
													localStorage.setItem('end_time',end_time);
													localStorage.setItem("vaild_list",res.data.data.vaild_list);
												}
										}).catch(function(error){
											alert("网络错误,请重试!")
											localStorage.clear();
											_this.$router.push({path: '/'});
										});
				};

				if(_this.$route.path == "/"){
					localStorage.setItem("statelocal",'true');
					_this.$router.push({path: '/personmanagement'});
				}
			}
			else{
				if(_this.$route.path == "/"){
					localStorage.setItem("statelocal",'true');
					_this.$router.push({path: '/personmanagement'});
				}
			}

		}else{
			localStorage.clear();
			_this.$router.push({path: '/'});
		}

}



